package logic

import (
	"context"
	"renting-demo/cart_srv/cart"

	"renting-demo/api/internal/svc"
	"renting-demo/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PruductAddCartLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPruductAddCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PruductAddCartLogic {
	return &PruductAddCartLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PruductAddCartLogic) PruductAddCart(req *types.PruductAddCartReq) (resp *types.Data, err error) {
	// todo: add your logic here and delete this line
	res, _ := l.svcCtx.CartServer.Add(context.Background(), &cart.AddCartRequest{
		UserId:   int64(req.UserId),
		GoodsId:  int64(req.GoodsId),
		GoodsNum: int64(req.GoodsNum),
	})
	if res.Status == "0" {
		return &types.Data{
			Code:    10001,
			Message: "商品加入购物车失败",
			Data:    nil,
		}, nil
	}
	return &types.Data{
		Code:    200,
		Message: "商品加入购物车成功",
		Data:    nil,
	}, nil
}
